package com.spy.material.controller;

import com.spy.common.core.domain.R;
import com.spy.material.dto.PurchaseOrderCreateDTO;
import com.spy.material.dto.PurchaseOrderQueryDTO;
import com.spy.material.service.IPurchaseOrderDetailService;
import com.spy.material.vo.PurchaseOrderDetailVO;
import com.spy.material.vo.PurchaseOrderPageVO;
import com.spy.material.vo.PurchaseOrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spy.common.annotation.Log;
import com.spy.common.core.controller.BaseController;
import com.spy.common.core.domain.AjaxResult;
import com.spy.common.enums.BusinessType;
import com.spy.material.domain.PurchaseOrder;
import com.spy.material.service.IPurchaseOrderService;
import com.spy.common.utils.poi.ExcelUtil;
import com.spy.common.core.page.TableDataInfo;

/**
 * 采购管理Controller
 *
 * @author twc
 * @date 2025-11-09
 */
@RestController
@RequestMapping("/material/purchases")
@Api(tags = "采购管理相关接口")
public class PurchaseOrderController extends BaseController
{
    @Autowired
    private IPurchaseOrderService purchaseOrderService;
    @Autowired
    private IPurchaseOrderDetailService purchaseOrderDetailService;

    @ApiOperation("采购列表数据的条件分页查询")
    @GetMapping("/page")
    public R<PurchaseOrderPageVO> Page(PurchaseOrderQueryDTO purchaseOrderQueryDTO) {
        PurchaseOrderPageVO purchaseOrderPageVO = purchaseOrderService.all(purchaseOrderQueryDTO);
        return R.ok(purchaseOrderPageVO);
    }

    @ApiOperation("添加采购单信息")
    @PostMapping("/add")
    public R add(@RequestBody PurchaseOrderCreateDTO purchaseOrderCreateDTO){
        purchaseOrderService.add(purchaseOrderCreateDTO);
        return R.ok();
    }

    @ApiOperation("根据采购单ID查询采购明细表")
    @GetMapping("/detail/{purchaseOrderId}")
    public R<List<PurchaseOrderDetailVO>> getPurchaseOrderDetailByPurchaseOrderId(@PathVariable Long purchaseOrderId) {
        List<PurchaseOrderDetailVO> list = purchaseOrderDetailService.getPurchaseOrderDetailByPurchaseOrderId(purchaseOrderId);
        return R.ok(list);
    }
}